<?php

namespace plugins\yifang_backend_account\middleware;

use \yifang\middleware\Middleware_contract;

class CheckAuth implements Middleware_contract
{
    /**
     *  处理请求
     */
    public function handle($request, \Closure $next)
    {
        if (app("YifangBackendAccount_L_Admin_rbac")->checkAccess()) {
            if (!app("YifangBackendAccount_L_Admin_rbac")->accessDecision()) {
                if(request()->isAjax()){
                    $response=apiResult(false,langPlugin("yifang_backend_account.admin.noPermission"),app("errorCode")::AUTH_ENTICATION);
                    return jsonResponse($response);
                }else{
                    return view("admin/error/noAuth");
                }
            }
        }
        $response = $next($request);
        return $response;
    }
}


